/*
 * Copyright 2010 bedatadriven
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.bedatadriven.mso.excel;

public class CellAddress {
  private String value;

  private CellAddress(String value) {
    this.value = value;
  }

  public static CellAddress rowCol(int row, int col) {
    return new CellAddress(cellCoordinate(row, col));
  }

  public static CellAddress rowColRange(int fromRow, int fromCol, int toRow, int toCol) {
    return new CellAddress(cellCoordinate(fromRow, fromCol) + ":" + cellCoordinate(toRow, toCol));
  }

  private static String cellCoordinate(int row, int col) {
    return String.valueOf(colLetter(col)) +
        Integer.toString(row);
  }

  private static char colLetter(int row) {
    return (char)('A' + row - 1);
  }

  @Override
  public String toString() {
    return value;
  }
}
